import pygame
from pygame.locals import *
from point import Point
class Player(object):
    def __init__(self,  partingLine, init_position = Point(0,0),color = (10,10,255)):
        self.position = init_position
        self.partingLine = partingLine
        self.color = color
        self.size = self.partingLine.size
        self.m = self.partingLine.height // self.size # x
        self.n = self.partingLine.width // self.size  # y

    def positionConstraint(self):
        if (self.position.x >= 0 and self.position.x < self.n) and (self.position.y >= 0 and self.position.y < self.m):
            return True
        else: return False
    def moveUp(self):
        pass 
    def getKey(self, key):
        #print(self.position.x, self.position.y)
        if key[K_w] and self.positionConstraint():
            self.position.y -= 1
        if key[K_s] and self.positionConstraint():
            self.position.y += 1
        if key[K_d] and self.positionConstraint():
            self.position.x += 1
        if key[K_a] and self.positionConstraint():
            self.position.x -= 1

    def draw(self):
        x = self.position.x * self.partingLine.size + self.partingLine.line_width
        y = self.position.y * self.partingLine.size + self.partingLine.line_width
        l = self.partingLine.size - self.partingLine.line_width
        pygame.draw.rect(self.partingLine.screen, self.color,(x, y,l ,l), 0)


